home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 October / Macformat17.cdr / Shareware City / Developers / halma-111-c / Halma ƒ / Shell ƒ / help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-11  |  20.8 KB  |  818 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        help.c
  4.  
  5. Purpose:    This module handles displaying the different help windows.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program in a file named "GNU General Public License".
  19. If not, write to the Free Software Foundation, 675 Mass Ave,
  20. Cambridge, MA 02139, USA.
  21.  
  22. \**********************************************************************/
  23.  
  24. #include "help.h"
  25. #include "environment.h"
  26. #include "util.h"
  27. #include "buttons.h"
  28. #include "timing.h"
  29. #include "program globals.h"
  30.  
  31. #define DEAD_SPACE_TOP        10
  32. #define DEAD_SPACE_LEFT        10
  33. #define DEAD_SPACE_BOTTOM    27
  34. #define DEAD_SPACE_RIGHT    10
  35. #define    TEXT_RECT_WIDTH        405
  36. #define    TEXT_RECT_HEIGHT    250
  37. #define    BUTTON_WIDTH        60
  38. #define    BUTTON_HEIGHT        60
  39. #define    XREF_DEAD_SPACE_TOP    5
  40. #define XREF_TEXT_WIDTH        46
  41. #define    XREF_WIDTH            70
  42. #define    XREF_HEIGHT            17
  43. #define    XREF_GAP            5
  44.  
  45. #define MAX_MAIN_TOPICS        4
  46. #define    MAX_SUB_TOPICS        5
  47.  
  48. #define    MAX_XREFS            4
  49.  
  50. #define MAIN_TOPIC_ID        600
  51. #define FIRST_SUB_TOPIC_ID    610
  52.  
  53. #define theWindowWidth (boundsRect.right-boundsRect.left)
  54. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  55. #define CorrectTime 1
  56. #define SCROLL_BOX_SIZE        20
  57.  
  58. typedef unsigned char    **CharHandle;
  59.  
  60. typedef struct
  61. {
  62.     long            offset;
  63.     short            lineHeight;
  64.     short            fontDescent;
  65.     short            fontNum;
  66.     unsigned char    fontStyle;
  67.     unsigned char    unused1;
  68.     short            fontSize;
  69.     short            unused2;
  70.     short            unused3;
  71.     short            unused4;
  72. } OneStyle;
  73.  
  74. typedef struct
  75. {
  76.     short        numStyles;
  77.     OneStyle    theStyle[31];
  78. } StylRec, *StylPtr, **StylHandle;
  79.  
  80. enum
  81. {
  82.     kLeft=0,
  83.     kCenter
  84. };
  85.  
  86. short            gNumMainTopics;
  87. short            gNumSubTopics[MAX_MAIN_TOPICS];
  88. short            gNumXRefs[MAX_MAIN_TOPICS][MAX_SUB_TOPICS];
  89.  
  90. CIconHandle        gMainTopicIconColor[MAX_MAIN_TOPICS];
  91. Handle            gMainTopicIconBW[MAX_MAIN_TOPICS];
  92. Str31            gMainTopicTitle[MAX_MAIN_TOPICS];
  93. Rect            gMainTopicRect[MAX_MAIN_TOPICS];
  94.  
  95. CIconHandle        gSubTopicIconColor[MAX_MAIN_TOPICS][MAX_SUB_TOPICS];
  96. Handle            gSubTopicIconBW[MAX_MAIN_TOPICS][MAX_SUB_TOPICS];
  97. Str31            gSubTopicTitle[MAX_MAIN_TOPICS][MAX_SUB_TOPICS];
  98. Rect            gSubTopicRect[MAX_MAIN_TOPICS][MAX_SUB_TOPICS];
  99. short            gSubTopicID[MAX_MAIN_TOPICS][MAX_SUB_TOPICS];
  100.  
  101. short            gXRefIndex[MAX_MAIN_TOPICS][MAX_SUB_TOPICS][MAX_XREFS];
  102. Rect            gXRefRect[MAX_XREFS];
  103.  
  104. short            gStickyTopic;
  105. short            gStickySubTopic;
  106.  
  107. short            gMainTopicShowing;        /* saved in prefs file */
  108. short            gSubTopicShowing;        /* saved in prefs file */
  109.  
  110. Rect            gTextRect;
  111. CharHandle        gTheText;
  112. StylHandle        gTheStyle;
  113.  
  114. /*-----------------------------------------------------------------------------------*/
  115. /* internal stuff for help.c                                                         */
  116.  
  117. void SetupTheHelpWindow(WindowDataHandle theData);
  118. void ShutdownTheHelpWindow(WindowDataHandle theData);
  119. void InitializeTheHelpWindow(WindowDataHandle theData);
  120. void OpenTheHelpWindow(WindowDataHandle theData);
  121. void KeyPressedInHelpWindow(WindowDataHandle theData, unsigned char keyPressed);
  122. void MouseClickedInHelpWindow(WindowDataHandle theData, Point mouseLoc);
  123. void DrawTheHelpWindow(short theDepth);
  124. void DrawTheText(CharHandle theText, StylHandle theStyleHandle, short theJust,
  125.     short theMode, Rect theRect);
  126. void DrawTheShadowBox(Rect theRect);
  127. short ParseRawTitle(Str255 theTitle, short *xRef, short *numXRefs);
  128. void GoToPage(WindowDataHandle theData, short mainTopic, short subTopic,
  129.     Boolean updateNow);
  130. void PushInSubTopic(WindowDataHandle theData);
  131. void PullOutSubTopic(WindowDataHandle theData, short mainTopic);
  132. void HighlightSubTopic(WindowDataHandle theData, short mainTopic, short subTopic,
  133.     Boolean isHighlighted);
  134. void GetTextResources(short mainTopic, short subTopic);
  135. void DisposeTextResources(void);
  136. void FullScrollRight(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect);
  137. void CalculateXRefInfo(short index, short *mainTopic, short *subTopic, Str255 name);
  138.  
  139.  
  140. short HelpWindowDispatch(WindowDataHandle theData, short theMessage, unsigned long misc)
  141. {
  142.     unsigned char    theChar;
  143.     Point            thePoint;
  144.     short            theDepth;
  145.     
  146.     switch (theMessage)
  147.     {
  148.         case kUpdate:
  149.             theDepth=misc&0x7fff;
  150.             DrawTheHelpWindow(theDepth);
  151.             return kSuccess;
  152.             break;
  153.         case kKeydown:
  154.             theChar=misc&charCodeMask;
  155.             KeyPressedInHelpWindow(theData, theChar);
  156.             return kSuccess;
  157.             break;
  158.         case kMousedown:
  159.             thePoint.h=(misc>>16)&0x7fff;
  160.             thePoint.v=misc&0x7fff;
  161.             MouseClickedInHelpWindow(theData, thePoint);
  162.             return kSuccess;
  163.             break;
  164.         case kOpen:
  165.             OpenTheHelpWindow(theData);
  166.             return kSuccess;
  167.             break;
  168.         case kInitialize:
  169.             InitializeTheHelpWindow(theData);
  170.             return kSuccess;
  171.             break;
  172.         case kStartup:
  173.             SetupTheHelpWindow(theData);
  174.             return kSuccess;
  175.             break;
  176.         case kShutdown:
  177.             ShutdownTheHelpWindow(theData);
  178.             return kSuccess;
  179.             break;
  180.     }
  181.     
  182.     return kFailure;        /* revert to default processing for all other messages */
  183. }
  184.  
  185. void SetupTheHelpWindow(WindowDataHandle theData)
  186. {
  187.     short            i,j;
  188.     unsigned char    *helpStr="\pHelp";
  189.     Handle            temp;
  190.     short            iconID;
  191.     short            centeringOffset;
  192.     
  193.     temp=GetResource('STR#', MAIN_TOPIC_ID);
  194.     gNumMainTopics=**((short**)temp);
  195.     ReleaseResource(temp);
  196.     for (i=0; i<gNumMainTopics; i++)
  197.     {
  198.         temp=GetResource('STR#', FIRST_SUB_TOPIC_ID+i);
  199.         gNumSubTopics[i]=**((short**)temp);
  200.         ReleaseResource(temp);
  201.     }
  202.     centeringOffset=DEAD_SPACE_TOP;
  203.     for (i=0; i<gNumMainTopics; i++)
  204.     {
  205.         GetIndString(gMainTopicTitle[i], MAIN_TOPIC_ID, i+1);
  206.         iconID=ParseRawTitle(gMainTopicTitle[i], 0L, 0L);
  207.         if (gHasColorQD)
  208.             gMainTopicIconColor[i]=GetCIcon(iconID);
  209.         gMainTopicIconBW[i]=GetIcon(iconID);
  210.         SetRect(&gMainTopicRect[i], DEAD_SPACE_LEFT, centeringOffset+BUTTON_HEIGHT*i,
  211.             DEAD_SPACE_LEFT+BUTTON_WIDTH, centeringOffset+BUTTON_HEIGHT*(i+1));
  212.         
  213.         for (j=0; j<gNumSubTopics[i]; j++)
  214.         {
  215.             GetIndString(gSubTopicTitle[i][j], FIRST_SUB_TOPIC_ID+i, j+1);
  216.             iconID=ParseRawTitle(gSubTopicTitle[i][j], gXRefIndex[i][j], &(gNumXRefs[i][j]));
  217.             gSubTopicID[i][j]=iconID;
  218.             if (gHasColorQD)
  219.                 gSubTopicIconColor[i][j]=GetCIcon(iconID);
  220.             gSubTopicIconBW[i][j]=GetIcon(iconID);
  221.             SetRect(&gSubTopicRect[i][j], DEAD_SPACE_LEFT+BUTTON_WIDTH*(j+1),
  222.                 centeringOffset+BUTTON_HEIGHT*i, DEAD_SPACE_LEFT+BUTTON_WIDTH*(j+2),
  223.                 centeringOffset+BUTTON_HEIGHT*(i+1));
  224.         }
  225.     }
  226.     
  227.     for (i=0; i<MAX_XREFS; i++)
  228.     {
  229.         SetRect(&gXRefRect[i], XREF_TEXT_WIDTH+DEAD_SPACE_LEFT+BUTTON_WIDTH+DEAD_SPACE_LEFT+
  230.             i*(XREF_WIDTH+XREF_GAP), DEAD_SPACE_TOP+TEXT_RECT_HEIGHT+XREF_DEAD_SPACE_TOP,
  231.             XREF_TEXT_WIDTH+DEAD_SPACE_LEFT+BUTTON_WIDTH+DEAD_SPACE_LEFT+
  232.             i*(XREF_WIDTH+XREF_GAP)+XREF_WIDTH, DEAD_SPACE_TOP+TEXT_RECT_HEIGHT+
  233.             XREF_DEAD_SPACE_TOP+XREF_HEIGHT);
  234.     }
  235.     
  236.     gTheText=gTheStyle=0L;
  237.     GoToPage(0L, gMainTopicShowing, gSubTopicShowing, FALSE);
  238.     
  239.     SetRect(&gTextRect, DEAD_SPACE_LEFT+BUTTON_WIDTH+DEAD_SPACE_LEFT, DEAD_SPACE_TOP,
  240.         DEAD_SPACE_LEFT+BUTTON_WIDTH+DEAD_SPACE_LEFT+TEXT_RECT_WIDTH,
  241.         DEAD_SPACE_TOP+TEXT_RECT_HEIGHT);
  242.     
  243.     (**theData).maxDepth=8;
  244.     (**theData).windowWidth=DEAD_SPACE_LEFT+BUTTON_WIDTH+DEAD_SPACE_LEFT+
  245.         TEXT_RECT_WIDTH+DEAD_SPACE_RIGHT;
  246.     (**theData).windowHeight=DEAD_SPACE_TOP+TEXT_RECT_HEIGHT+DEAD_SPACE_BOTTOM;
  247.     (**theData).windowType=noGrowDocProc;    /* document-looking thing */
  248.     (**theData).hasCloseBox=TRUE;
  249.     (**theData).windowBounds.top=50;
  250.     (**theData).windowBounds.left=6;
  251.     SetIndWindowTitle(kHelp, helpStr);
  252. }
  253.  
  254. void ShutdownTheHelpWindow(WindowDataHandle theData)
  255. {
  256.     short            i,j;
  257.     
  258.     for (i=0; i<gNumMainTopics; i++)
  259.     {
  260.         if (gHasColorQD)
  261.             DisposeCIcon(gMainTopicIconColor[i]);
  262.         ReleaseResource(gMainTopicIconBW[i]);
  263.         
  264.         for (j=0; j<gNumSubTopics[i]; j++)
  265.         {
  266.             if (gHasColorQD)
  267.                 DisposeCIcon(gSubTopicIconColor[i][j]);
  268.             ReleaseResource(gSubTopicIconColor[i][j]);
  269.         }
  270.     }
  271.     DisposeTextResources();
  272. }
  273.  
  274. void InitializeTheHelpWindow(WindowDataHandle theData)
  275. {
  276.     (**theData).initialTopLeft.v=(**theData).windowBounds.top-9;
  277.     (**theData).initialTopLeft.h=(**theData).windowBounds.left;
  278.     gStickyTopic=-1;
  279. }
  280.  
  281. void OpenTheHelpWindow(WindowDataHandle theData)
  282. {
  283.     (**theData).offscreenNeedsUpdate=TRUE;
  284. }
  285.  
  286. void KeyPressedInHelpWindow(WindowDataHandle theData, unsigned char keyPressed)
  287. {
  288.     short            oldTopic;
  289.     
  290.     ObscureCursor();
  291.     
  292.     switch (keyPressed)
  293.     {
  294.         case 0x1d:                                        /* right arrow */
  295.             if (gStickyTopic==-1)
  296.             {
  297.                 gSubTopicShowing++;
  298.                 if (gSubTopicShowing>=gNumSubTopics[gMainTopicShowing])
  299.                 {
  300.                     gSubTopicShowing=0;
  301.                     gMainTopicShowing++;
  302.                     if (gMainTopicShowing>=gNumMainTopics)
  303.                         gMainTopicShowing=0;
  304.                 }
  305.                 GoToPage(theData, gMainTopicShowing, gSubTopicShowing, TRUE);
  306.             }
  307.             else
  308.             {
  309.                 if (gStickySubTopic!=-1)
  310.                     HighlightSubTopic(theData, gStickyTopic, gStickySubTopic, FALSE);
  311.                 gStickySubTopic++;
  312.                 if (gStickySubTopic>=gNumSubTopics[gStickyTopic])
  313.                     gStickySubTopic=0;
  314.                 HighlightSubTopic(theData, gStickyTopic, gStickySubTopic, TRUE);
  315.             }
  316.             break;
  317.         case 0x1c:                                        /* left arrow */
  318.             if (gStickyTopic==-1)
  319.             {
  320.                 gSubTopicShowing--;
  321.                 if (gSubTopicShowing<0)
  322.                 {
  323.                     gMainTopicShowing--;
  324.                     if (gMainTopicShowing<0)
  325.                         gMainTopicShowing=gNumMainTopics-1;
  326.                     gSubTopicShowing=gNumSubTopics[gMainTopicShowing]-1;
  327.                 }
  328.                 GoToPage(theData, gMainTopicShowing, gSubTopicShowing, TRUE);
  329.             }
  330.             else
  331.             {
  332.                 if (gStickySubTopic!=-1)
  333.                     HighlightSubTopic(theData, gStickyTopic, gStickySubTopic, FALSE);
  334.                 gStickySubTopic--;
  335.                 if (gStickySubTopic<0)
  336.                     gStickySubTopic=gNumSubTopics[gStickyTopic]-1;
  337.                 HighlightSubTopic(theData, gStickyTopic, gStickySubTopic, TRUE);
  338.             }
  339.             break;
  340.         case 0x1e:                                        /* up arrow */
  341.             if (gStickyTopic!=-1)
  342.             {
  343.                 oldTopic=gStickyTopic;
  344.                 PushInSubTopic(theData);
  345.                 gStickyTopic=oldTopic-1;
  346.                 if (gStickyTopic<0)
  347.                     gStickyTopic=gNumMainTopics-1;
  348.             }
  349.             else gStickyTopic=gNumMainTopics-1;
  350.             
  351.             PullOutSubTopic(theData, gStickyTopic);
  352.             break;
  353.         case 0x1f:                                        /* down arrow */
  354.             if (gStickyTopic!=-1)
  355.             {
  356.                 oldTopic=gStickyTopic;
  357.                 PushInSubTopic(theData);
  358.                 gStickyTopic=oldTopic+1;
  359.                 if (gStickyTopic>=gNumMainTopics)
  360.                     gStickyTopic=0;
  361.             }
  362.             else gStickyTopic=0;
  363.             
  364.             PullOutSubTopic(theData, gStickyTopic);
  365.             break;
  366.         case 0x1b:                                        /* escape key */
  367.             if (gStickyTopic!=-1)
  368.                 PushInSubTopic(theData);
  369.             else CloseTheWindow(theData);
  370.             break;
  371.         case 0x03:
  372.         case 0x0d:
  373.             if (gStickyTopic==-1)
  374.             {
  375.                 gStickyTopic=gMainTopicShowing;
  376.                 PullOutSubTopic(theData, gStickyTopic);
  377.             }
  378.             else
  379.             {
  380.                 if (gStickySubTopic!=-1)
  381.                 {
  382.                     HighlightSubTopic(theData, gStickyTopic, gStickySubTopic, FALSE);
  383.                     GoToPage(theData, gStickyTopic, gStickySubTopic, TRUE);
  384.                 }
  385.                 else PushInSubTopic(theData);
  386.             }
  387.             break;
  388.     }
  389. }
  390.  
  391. void MouseClickedInHelpWindow(WindowDataHandle theData, Point mouseLoc)
  392. {
  393.     short            newTopic;
  394.     Boolean            isColor;
  395.     short            i;
  396.     Str255            name;
  397.     short            newMain, newSub;
  398.     
  399.     isColor=((**theData).windowDepth>2);
  400.     newTopic=-1;
  401.     
  402.     for (i=0; i<gNumXRefs[gMainTopicShowing][gSubTopicShowing]; i++)
  403.     {
  404.         if (PtInRect(mouseLoc, &gXRefRect[i]))
  405.         {
  406.             CalculateXRefInfo(gXRefIndex[gMainTopicShowing][gSubTopicShowing][i],
  407.                 &newMain, &newSub, name);
  408.             
  409.             if ((newMain!=-1) && (newSub!=-1))
  410.             {
  411.                 if (Track3DButton(&gXRefRect[i], name, 0L, (**theData).windowDepth))
  412.                 {
  413.                     GoToPage(theData, newMain, newSub, TRUE);
  414.                     return;
  415.                 }
  416.             }
  417.         }
  418.     }
  419.     
  420.     for (i=0; i<gNumMainTopics; i++)
  421.     {
  422.         if (PtInRect(mouseLoc, &gMainTopicRect[i]))
  423.         {
  424.             newTopic=i;
  425.             i=gNumMainTopics;
  426.         }
  427.     }
  428.     
  429.     if (newTopic!=-1)
  430.     {
  431.         if (newTopic==gStickyTopic)
  432.             PushInSubTopic(theData);
  433.         else
  434.         {
  435.             if (gStickyTopic!=-1)
  436.                 PushInSubTopic(theData);
  437.             PullOutSubTopic(theData, newTopic);
  438.             gStickyTopic=newTopic;
  439.         }
  440.     }
  441.     
  442.     if ((gStickyTopic!=-1) && (newTopic==-1))
  443.     {
  444.         for (i=0; i<gNumSubTopics[gStickyTopic]; i++)
  445.         {
  446.             if (PtInRect(mouseLoc, &gSubTopicRect[gStickyTopic][i]))
  447.             {
  448.                 if (gStickySubTopic!=-1)
  449.                     HighlightSubTopic(theData, gStickyTopic, gStickySubTopic, FALSE);
  450.                 gStickySubTopic=-1;
  451.                 
  452.                 if (Track3DButton(&gSubTopicRect[gStickyTopic][i],
  453.                     gSubTopicTitle[gStickyTopic][i], isColor ?
  454.                     (Handle)gSubTopicIconColor[gStickyTopic][i] :
  455.                     gSubTopicIconBW[gStickyTopic][i], (**theData).windowDepth))
  456.                 {
  457.                     newTopic=i;
  458.                     i=gNumSubTopics[gStickyTopic];
  459.                 }
  460.             }
  461.         }
  462.         if (newTopic!=-1)
  463.             GoToPage(theData, gStickyTopic, newTopic, TRUE);
  464.         else
  465.             PushInSubTopic(theData);
  466.     }
  467. }
  468.  
  469. void DrawTheHelpWindow(short theDepth)
  470. {
  471.     GrafPtr            curPort;
  472.     short            i,j;
  473.     Boolean            isColor;
  474.     Rect            tempRect;
  475.     Str255            theStr;
  476.     short            dummy1, dummy2;
  477.     
  478.     isColor=(theDepth>2);
  479.     
  480.     GetPort(&curPort);
  481.     EraseRect(&(curPort->portRect));
  482.     
  483.     DrawTheShadowBox(gTextRect);
  484.     if (gTheText!=0L)
  485.     {
  486.         tempRect=gTextRect;
  487.         InsetRect(&tempRect, 8, 4);
  488.         DrawTheText(gTheText, gTheStyle, kLeft, srcOr, tempRect);
  489.     }
  490.     
  491.     for (i=0; i<gNumMainTopics; i++)
  492.     {
  493.         Draw3DButton(&gMainTopicRect[i], gMainTopicTitle[i],
  494.             isColor ? (Handle)gMainTopicIconColor[i] : gMainTopicIconBW[i],
  495.             theDepth, (i==gStickyTopic));
  496.         if (i==gStickyTopic)
  497.         {
  498.             for (j=0; j<gNumSubTopics[i]; j++)
  499.             {
  500.                 Draw3DButton(&gSubTopicRect[i][j], gSubTopicTitle[i][j],
  501.                 isColor ? (Handle)gSubTopicIconColor[i][j] : gSubTopicIconBW[i][j],
  502.                 theDepth, (j==gStickySubTopic));
  503.             }
  504.         }
  505.     }
  506.     
  507.     for (i=0; i<gNumXRefs[gMainTopicShowing][gSubTopicShowing]; i++)
  508.     {
  509.         CalculateXRefInfo(gXRefIndex[gMainTopicShowing][gSubTopicShowing][i],
  510.             &dummy1, &dummy2, theStr);
  511.         Draw3DButton(&gXRefRect[i], theStr, 0L, theDepth, FALSE);
  512.     }
  513.     if (gNumXRefs[gMainTopicShowing][gSubTopicShowing]>0)
  514.     {
  515.         MoveTo(gXRefRect[0].left-XREF_TEXT_WIDTH, gXRefRect[0].bottom-5);
  516.         TextFont(geneva);
  517.         TextSize(9);
  518.         DrawString("\pSee also:");
  519.     }
  520. }
  521.  
  522. void DrawTheText(CharHandle theText, StylHandle theStyleHandle, short theJust,
  523.     short theMode, Rect theRect)
  524. {
  525.     short            i, numStyles;
  526.     long            textPos;
  527.     long            maxOffset;
  528.     Str255            thisLine;
  529.     Boolean            notDoneYet;
  530.     unsigned char    thisChar;
  531.     short            theRow, theCol;
  532.     unsigned char    lastEnd, thisEnd;
  533.     Boolean            overRun;
  534.     
  535.     numStyles=(**theStyleHandle).numStyles;
  536.     textPos=0L;
  537.     theRow=theRect.top+(**theStyleHandle).theStyle[0].fontDescent+1;
  538.     theCol=theRect.left;
  539.     thisLine[0]=0x00;
  540.     lastEnd=0;
  541.     for (i=0; i<numStyles; i++)
  542.     {
  543.         if (i==numStyles-1)
  544.             maxOffset=GetHandleSize(theText);
  545.         else
  546.             maxOffset=(**theStyleHandle).theStyle[i+1].offset;
  547.         
  548.         TextFont((**theStyleHandle).theStyle[i].fontNum);
  549.         TextFace((**theStyleHandle).theStyle[i].fontStyle);
  550.         TextSize((**theStyleHandle).theStyle[i].fontSize);
  551.         TextMode(theMode);
  552.         
  553.         while (textPos<maxOffset)
  554.         {
  555.             notDoneYet=TRUE;
  556.             while ((textPos<maxOffset) && (notDoneYet))
  557.             {
  558.                 thisChar=thisLine[++thisLine[0]]=(*theText)[textPos++];
  559.                 notDoneYet=((thisChar!=' ') && (thisChar!=0x0d));
  560.             }
  561.             
  562.             thisEnd=thisLine[0];
  563.             overRun=(theRect.right-theCol<=StringWidth(thisLine));
  564.             
  565.             if ((overRun) || (thisChar==0x0d) || (textPos==maxOffset))
  566.             {
  567.                 if (overRun)
  568.                     thisLine[0]=lastEnd;
  569.                 if (theJust==kCenter)
  570.                     MoveTo((theRect.right-theRect.left-StringWidth(thisLine))/2+
  571.                             theCol, theRow);
  572.                 else
  573.                     MoveTo(theCol, theRow);
  574.                 theCol+=StringWidth(thisLine);
  575.                 DrawString(thisLine);
  576.                 if (overRun)
  577.                 {
  578.                     BlockMove(&thisLine[lastEnd+1], &thisLine[1], thisEnd-lastEnd+1);
  579.                     if (thisEnd>=lastEnd)
  580.                     {
  581.                         thisLine[0]=thisEnd-lastEnd-1;
  582.                         textPos--;
  583.                     }
  584.                     else
  585.                         thisEnd=thisLine[0]=0x00;
  586.                 }
  587.                 else thisLine[0]=0x00;
  588.                 if ((overRun) || (thisChar==0x0d))
  589.                 {
  590.                     theRow+=(**theStyleHandle).theStyle[i].lineHeight;
  591.                     theCol=theRect.left;
  592.                 }
  593.             }
  594.             
  595.             lastEnd=thisEnd;
  596.         }
  597.         
  598.         if (thisLine[0]!=0x00)
  599.         {
  600.             if (theJust==kCenter)
  601.                 MoveTo((theRect.right-theRect.left-StringWidth(thisLine))/2+
  602.                         theCol, theRow);
  603.             else
  604.                 MoveTo(theCol, theRow);
  605.             theCol+=StringWidth(thisLine);
  606.             DrawString(thisLine);
  607.             thisLine[0]=0x00;
  608.         }
  609.     }
  610.     TextMode(srcOr);
  611. }
  612.  
  613. void DrawTheShadowBox(Rect theRect)
  614. {
  615.     theRect.right-=2;
  616.     theRect.bottom-=2;
  617.     FrameRect(&theRect);
  618.     MoveTo(theRect.left+3, theRect.bottom+1);
  619.     Line(theRect.right-theRect.left-2, 0);
  620.     Line(0, -theRect.bottom+theRect.top+3);
  621.     MoveTo(theRect.left+3, theRect.bottom);
  622.     Line(theRect.right-theRect.left-3, 0);
  623.     Line(0, -theRect.bottom+theRect.top+4);
  624. }
  625.  
  626. short ParseRawTitle(Str255 theTitle, short *xRef, short *numXRefs)
  627. {
  628.     Str255            numStr;
  629.     unsigned long    result;
  630.     short            i,j;
  631.     Boolean            gotbullet;
  632.     Boolean            moreXRefs;
  633.     
  634.     if (xRef!=0L)
  635.     {
  636.         *numXRefs=0;
  637.         for (j=1, gotbullet=FALSE; ((j<=theTitle[0]) && (!gotbullet)); j++)
  638.             gotbullet=(theTitle[j]=='%');
  639.         if (gotbullet)
  640.         {
  641.             i=j;
  642.             do
  643.             {
  644.                 numStr[0]=0x00;
  645.                 while ((numStr[0]<=theTitle[0]-i) &&
  646.                     (((numStr[numStr[0]]=theTitle[i+(numStr[0]++)]))!=' ')) {}
  647.                 if (numStr[numStr[0]]==' ')
  648.                 {
  649.                     moreXRefs=TRUE;
  650.                     i+=numStr[0];
  651.                     numStr[0]--;
  652.                 }
  653.                 else moreXRefs=FALSE;
  654.                 StringToNum(numStr, &result);
  655.                 xRef[(*numXRefs)++]=result;
  656.             }
  657.             while (moreXRefs);
  658.             theTitle[0]=j-2;
  659.         }
  660.     }
  661.     numStr[0]=0x00;
  662.     while ((numStr[numStr[0]]=theTitle[++numStr[0]])!=' ') {}
  663.     theTitle[0]-=numStr[0];
  664.     Mymemcpy(&theTitle[1], &theTitle[numStr[0]+1], theTitle[0]);
  665.     numStr[0]--;
  666.     StringToNum(numStr, &result);
  667.     return result;
  668. }
  669.  
  670. void GoToPage(WindowDataHandle theData, short mainTopic, short subTopic,
  671.     Boolean updateNow)
  672. {
  673.     DisposeTextResources();
  674.     GetTextResources(mainTopic, subTopic);
  675.     gMainTopicShowing=mainTopic;
  676.     gSubTopicShowing=subTopic;
  677.     gStickyTopic=gStickySubTopic=-1;
  678.     if (updateNow)
  679.     {
  680.         (**theData).offscreenNeedsUpdate=TRUE;
  681.         UpdateTheWindow(theData);
  682.     }
  683. }
  684.  
  685. void PushInSubTopic(WindowDataHandle theData)
  686. {
  687.     gStickyTopic=-1;
  688.     (**theData).offscreenNeedsUpdate=TRUE;
  689.     UpdateTheWindow(theData);
  690. }
  691.  
  692. void PullOutSubTopic(WindowDataHandle theData, short mainTopic)
  693. {
  694.     short            i;
  695.     short            theDepth;
  696.     Boolean            isColor;
  697.     Rect            tempRect;
  698.     
  699.     gStickySubTopic=-1;
  700.     
  701.     isColor=(theDepth=(**theData).windowDepth)>2;
  702.     
  703.     SetPortToOffscreen(theData);
  704.     for (i=0; i<gNumSubTopics[mainTopic]; i++)
  705.     {
  706.         Draw3DButton(&gSubTopicRect[mainTopic][i], gSubTopicTitle[mainTopic][i],
  707.         isColor ? (Handle)gSubTopicIconColor[mainTopic][i] :
  708.         gSubTopicIconBW[mainTopic][i], theDepth, FALSE);
  709.     }
  710.     RestorePortToScreen(theData);
  711.  
  712.     Draw3DButton(&gMainTopicRect[mainTopic], gMainTopicTitle[mainTopic],
  713.         isColor ? (Handle)gMainTopicIconColor[mainTopic] :
  714.         gMainTopicIconBW[mainTopic], theDepth, TRUE);
  715.     
  716.     tempRect=gSubTopicRect[mainTopic][0];
  717.     tempRect.right=gSubTopicRect[mainTopic][gNumSubTopics[mainTopic]-1].right;
  718.     FullScrollRight(GetOffscreenGrafPtr(theData), GetWindowGrafPtr(theData), tempRect);
  719.     
  720.     (**theData).offscreenNeedsUpdate=TRUE;
  721. }
  722.  
  723. void HighlightSubTopic(WindowDataHandle theData, short mainTopic, short subTopic,
  724.     Boolean isHighlighted)
  725. {
  726.     Draw3DButton(&gSubTopicRect[mainTopic][subTopic], gSubTopicTitle[mainTopic][subTopic],
  727.         ((**theData).windowDepth>2) ? (Handle)gSubTopicIconColor[mainTopic][subTopic] :
  728.         gSubTopicIconBW[mainTopic][subTopic], (**theData).windowDepth, isHighlighted);
  729.     
  730.     (**theData).offscreenNeedsUpdate=TRUE;
  731. }
  732.  
  733. void GetTextResources(short mainTopic, short subTopic)
  734. {
  735.     short            resID;
  736.     
  737.     DisposeTextResources();
  738.     resID=gSubTopicID[mainTopic][subTopic];
  739.     gTheText=GetResource('TEXT', resID);
  740.     gTheStyle=GetResource('styl', resID);
  741. }
  742.  
  743. void DisposeTextResources(void)
  744. {
  745.     if (gTheText!=0L)
  746.         ReleaseResource(gTheText);
  747.     if (gTheStyle!=0L)
  748.         ReleaseResource(gTheStyle);
  749.     gTheText=gTheStyle=0L;
  750. }
  751.  
  752. void FullScrollRight(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect)
  753. {
  754.     Rect            sourceRect, destRect, scrollRect;
  755.     short            BoxSize;
  756.     
  757.     StartTiming();
  758.     
  759.     BoxSize=SCROLL_BOX_SIZE;
  760.     
  761.     destRect=sourceRect=scrollRect=boundsRect;
  762.     destRect.right=destRect.left+BoxSize;
  763.     sourceRect.left=boundsRect.right-BoxSize;
  764.     scrollRect.right=scrollRect.left+2*BoxSize;
  765.     
  766.     CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits),
  767.         &sourceRect, &destRect, 0, 0L);
  768.     
  769.     TimeCorrection(CorrectTime);
  770.     
  771.     while (scrollRect.right<=boundsRect.right)
  772.     {
  773.         StartTiming();
  774.         sourceRect.right-=BoxSize;
  775.         sourceRect.left-=BoxSize;
  776.         ScrollTheRect(&scrollRect, BoxSize, 0, 0L);
  777.         CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits),
  778.             &sourceRect, &destRect, 0, 0L);
  779.         TimeCorrection(CorrectTime);
  780.         scrollRect.right+=BoxSize;
  781.     }
  782.     
  783.     if (scrollRect.right!=boundsRect.right)
  784.         CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits),
  785.             &boundsRect, &boundsRect, 0, 0L);
  786. }
  787.  
  788. void CalculateXRefInfo(short index, short *mainTopic, short *subTopic, Str255 name)
  789. {
  790.     short            theMain, theSub;
  791.     unsigned char    *bad="\pBad XRef!";
  792.     
  793.     theMain=gNumMainTopics-1;
  794.     theSub=gNumSubTopics[theMain]-1;
  795.     while ((theMain>=0) && (index!=gSubTopicID[theMain][theSub]))
  796.     {
  797.         theSub--;
  798.         if (theSub<0)
  799.         {
  800.             theMain--;
  801.             theSub=gNumSubTopics[theMain];
  802.         }
  803.     }
  804.     
  805.     if (theMain<0)
  806.     {
  807.         Mymemcpy(name, bad, bad[0]+1);
  808.         *mainTopic=*subTopic=-1;
  809.     }
  810.     else
  811.     {
  812.         Mymemcpy(name, gSubTopicTitle[theMain][theSub],
  813.             gSubTopicTitle[theMain][theSub][0]+1);
  814.         *mainTopic=theMain;
  815.         *subTopic=theSub;
  816.     }
  817. }
  818.